package cc.idoone.codegen.table;

import cc.idoone.codegen.util.StringUtils;

/**
 * <p>
 * 表字段信息
 * </p>
 *
 * @author hemj
 * @date 2020-08-25
 */
public class TableField {

	private boolean primaryKey;
	private String name;
	private String type;
	private String propertyName;
	private ColumnJavaType columnType;
	private String comment;
	private String fill;

	public boolean isPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(boolean primaryKey) {
		this.primaryKey = primaryKey;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getPropertyName() {
		return propertyName;
	}

	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}

	public ColumnJavaType getColumnType() {
		return columnType;
	}

	public void setColumnType(ColumnJavaType columnType) {
		this.columnType = columnType;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public String getFill() {
		return fill;
	}

	public void setFill(String fill) {
		this.fill = fill;
	}

	/**
	 * 按 JavaBean 规则来生成 get 和 set 方法名称部分
	 */
	public String getCapitalName() {
		if (propertyName.length() <= 1) {
			return propertyName.toUpperCase();
		}
		String setGetName = propertyName;
		if (ColumnJavaType.BOOLEAN.getName().equalsIgnoreCase(columnType.getName())) {
			setGetName = StringUtils.removeIsPrefixIfBoolean(setGetName, Boolean.class);
		}
		// 第一个字母 小写、 第二个字母 大写 ，特殊处理
		if (Character.isLowerCase(setGetName.charAt(0))
				&& Character.isUpperCase(setGetName.charAt(1))) {
			return setGetName;
		}
		return setGetName.substring(0, 1).toUpperCase() + setGetName.substring(1);
	}

}
